package com.capgemini.diabeo.nav.model;

import java.io.Serializable;

import android.content.Context;
import android.support.v4.app.Fragment;

import com.capgemini.diabeo.model.Category;

/**
 * Classe représentant un sample, avec une classe et un titre
 * 
 * @author gudavo
 * 
 */
public class Sample implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5740642688283475175L;

	private CharSequence title;
	private Class<? extends Fragment> fragmentClass;
	private Category category;

	public Sample(Context context, int titleResId,
			Class<? extends Fragment> fragmentClass) {
		this.fragmentClass = fragmentClass;
		this.title = context.getResources().getString(titleResId);
	}

	public Sample(Context context, String title,
			Class<? extends Fragment> fragmentClass, Category category) {
		this.fragmentClass = fragmentClass;
		this.title = title;
		this.category = category;
	}

	public Category getCategory() {
		return category;
	}

	@Override
	public String toString() {
		return title.toString();
	}

	/**
	 * Getter pour title
	 * 
	 * @return le title
	 */
	public CharSequence getTitle() {
		return title;
	}

	/**
	 * Getter pour fragmentClass
	 * 
	 * @return le fragmentClass
	 */
	public Class<? extends Fragment> getFragmentClass() {
		return fragmentClass;
	}

	public Fragment createFragment() {
		try {
			return getFragmentClass().newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}